<link rel="stylesheet" href="__PUBLIC__/statics/default/assets/css/nav.css">

<div id="top-nav" data-am-sticky>
    <header class="max-block clear">
        <h1 class="icon">
            <a href="__APP__"></a>
        </h1>

        <div id="hamburger-btn" class="am-btn am-show-sm-only">
            <span class="am-icon-bars"></span>
        </div>

        <div class="top-nav-content clear">
            <div class="clear am-show-sm-only">
                <div class="close-btn am-btn">
                    <span class="iconfont">&#xe6b9;</span>
                </div>
            </div>
            <div class="lang">
                <div class="am-dropdown" data-am-dropdown="{boundary: '.am-topbar'}">
				
					<?php $sql="select * from website"; 
						$web_site_list = M()->query($sql); //AAA($web_site_list);
						$sql="select * from website where website_id=".$_SESSION['font_siteid'] ; 
						$current_site = M()->query($sql); //AAA($current_site);
						//AAA($current_site );
					?>
				
                    <button class="am-btn am-topbar-btn am-btn-sm am-dropdown-toggle" data-am-dropdown-toggle>
                        <i style="background:none"><img src="{$current_site[0][thumb]}" width="20" /></i>{$current_site[0][webname]} <span class="am-icon-caret-down"></span>
                    </button>
                    <ul class="am-dropdown-content">
						<?php foreach($web_site_list as $one_site){ ?>
                        <li><a href="{:U('Content/index',array('siteid'=>$one_site[website_id]))}">{$one_site[webname]}</a></li>
						<?php } ?>
                        
                    </ul>
                </div>
            </div>
            <ul class="pills clear">
                <li class="<?php if(!(cat_id())){ echo 'active';}  ?>"><a style="font-family:'微软雅黑'" href="{:U('Content/index')}"><?php echo getLangByKey($language,"Home"); ?></a></li>



				<?php $level1 = get_category();
					foreach($level1 as $key=> $level1_nav){
					if($key==0 || $key==2){
						$level2 = get_category($level1_nav['category_id']);
						$url_lv2 = U('Content/lists',array('cat_id'=>$level2[0]['category_id']));
				?>
				<li class="am-show-sm-only"><a style="font-family:'微软雅黑'" href="{$url_lv2}"><?php echo getLangByKey($language,$level1_nav['cat_name']); ?></a></li>
                <li  class="am-dropdown am-hide-sm-only <?php if(cat_id()==$level1_nav['category_id']){ echo 'active'; } ?>" data-am-dropdown>
                    <a style="font-family:'微软雅黑'" class="am-dropdown-toggle" data-am-dropdown-toggle href="{$url_lv2}"><?php echo getLangByKey($language,$level1_nav['cat_name']); ?> <span class="am-icon-angle-down"></span></a>

					<?php $level2 = get_category($level1_nav['category_id']); ?>

					<ul class="am-dropdown-content">
                        <div class="top-nav-drop">
                            <div class="second">
                                <div class="content">
                                    <ul>
										<?php foreach($level2   as $key2=> $level2_nav){
											$cat_url = U('Content/lists',array('cat_id'=>$level2_nav['category_id']));
											if($key==0 && $key2==1){

												$sub_list = cat2article($level2_nav['category_id'],$is_all=1,$num=2,$order='sub_id asc');

												$cat_url = U('Content/show',array('cat_id'=>$sub_list['lists'][0]['cat_id'],'id'=>$sub_list['lists'][0]['sub_id']));
											}
										?>
                                        <li class="<?php if ($key2==0) echo 'active'; ?>"><a href="{$cat_url}"> <?php echo getLangByKey($language,$level2_nav['cat_name']); ?><span style="font-weight: normal;" class="iconfont">&#xe6dd;</span></a></li>

										<?php } ?>



                                    </ul>
                                </div>
                            </div>
							<?php foreach($level2 as $key2=> $level2_nav){
								//if($key!=2) break;
								//AAA($level2_nav);
								
								$cat_url = U('Content/lists',array('cat_id'=>$level2_nav['category_id']));
								if($key==0 && $key2==1){

									$sub_list = cat2article($level2_nav['category_id'],$is_all=1,$num=2,$order='sub_id asc');

									$cat_url = U('Content/show',array('cat_id'=>$sub_list['lists'][0]['cat_id'],'id'=>$sub_list['lists'][0]['sub_id']));
								}
							?>
							<div class="third">

                                <div class="content <?php if($key2!=0) echo 'hide'; ?>">
                                    <ul>
										<li class="title"><a href="{$cat_url}"><?php echo getLangByKey($language,$level2_nav['cat_name']); ?> </a></li>

										<?php $nav_pro_list = cat2article($level2_nav['category_id'],$is_all=1,$num=5,$order='no'); 
										
											$pk = 'article_id';
											if($level1_nav['category_id']==2){
												$pk = 'product_id';
											}
											if($level2_nav['category_id']==13){
												$pk = 'sub_id';
											}
											if($level2_nav['category_id']==14){
												$pk = 'job_id';
											}
										?>
										<?php foreach($nav_pro_list['lists'] as $one_pro){ 
											if( in_array($level1_nav['category_id'] , array('2')) ){
										?>

											<li><a href="{$Think.const.CON_PATH}/{$one_pro[$pk]}/cat_id/{$one_pro[cat_id]}">{$one_pro['title']}</a></li>
										<?php }elseif($level1_nav['category_id']==8 && in_array($level2_nav['category_id'],array('9','10','11','12')) ){ ?>
											<li style="line-height:25px;font-weight:bold;font-size:16px;width:550px;-background:red;">
												<a  href="{$Think.const.CAT_PATH}/{$level2_nav[category_id]}">{$one_pro['description']}</a>
												<a class="nav_link" style="border: 1px solid #dfdfdf;margin-top:10px;" href="{$Think.const.CAT_PATH}/{$level2_nav[category_id]}"><i class="iconfont">&#xe6dd;</i><?php echo getLangByKey($language,"Read More..."); ?></a>
												
											</li>	
											
											
										<?php }elseif($level1_nav['category_id']==8 && in_array($level2_nav['category_id'],array('13','14')) ){ 
										//AAA($one_pro);
										?>
											<li><a href="{$Think.const.CON_PATH}/{$one_pro[$pk]}/cat_id/{$one_pro[cat_id]}">{$one_pro['title']}</a></li>	
										<?php }} ?>


                                    </ul>
                                </div>
							</div>
							<?php } ?>
                        </div>
                    </ul>
                </li>
				<?php }else{

				?>
					<li class="<?php if(cat_id()==$level1_nav['category_id']){ echo 'active'; } ?>"><a href="{$Think.const.CAT_PATH}/{$level1_nav['category_id']}"><?php echo getLangByKey($language,$level1_nav['cat_name']); ?></a></li>

				<?php }} ?>

            </ul>
        </div>
    </header>
</div>

<script>
$(function() {
    // top-nav下拉多级菜单active样式
    var index = $('#top-nav .pills>.active').index();
    $('#top-nav .pills .am-dropdown').on('open.dropdown.amui', function() {
        $(this).siblings('.am-dropdown').removeClass('active');
        $('#top-nav .pills>li').eq(index).addClass('active');
        $(this).addClass('active');
    });
    $('#top-nav .pills .am-dropdown').on('close.dropdown.amui', function() {
        if ($(this).index() != index) {
            $(this).removeClass('active');
        }
    });

    // top-nav下拉多级菜单2级宽度设置
    function setTopNavDropSecondWidth(parent) {
        if ($(window).width() <= 640) {
            return;
        }
        var bgWidth = parent.find('.second').outerWidth();
        var iconOffset = $('#top-nav .icon').offset().left;
        parent.find('.second .content').css('width', bgWidth - iconOffset - 50 + 'px');
    }
    $('#top-nav .pills .am-dropdown').on('mouseover', function() {
        setTopNavDropSecondWidth($(this));
    });
    $(window).on('resize', function() {
        setTopNavDropSecondWidth($('#top-nav .pills .am-dropdown.am-active'));
    });

    // top-nav下拉多级菜单 2 3级联动
    $('#top-nav .top-nav-drop .second .content ul li').on('mouseover', function() {
        $(this).siblings('li').removeClass('active');
        $(this).addClass('active');
        $(this).parents('.second').siblings('.third').find('.content').addClass('hide').eq($(this).index()).removeClass('hide');
    });

    // 下拉菜单触发
    $('#top-nav .pills .am-dropdown .am-dropdown-toggle')
        .off('click')
        .on('mouseover', function() {
            $(this).parents('.am-dropdown').dropdown('open');
        });

    $('#top-nav .pills .am-dropdown').on('mouseleave', function () {
        $(this).dropdown('close');
    });

    // 汉堡导航开启
    $('#hamburger-btn').on('click', function() {
        $('#top-nav .top-nav-content').addClass('show');
        setTimeout(function() {
            $('#top-nav .top-nav-content').addClass('in');
            $('#mask').addClass('show');
        }, 50);
    });
    // 汉堡导航关闭
    $('#top-nav .close-btn').on('click', function() {
        $('#top-nav .top-nav-content').removeClass('in');
        $('#mask').removeClass('show');
        setTimeout(function() {
            $('#top-nav .top-nav-content').removeClass('show');
        }, 200);
    });
});
</script>
